from django.db import models


# Create your models here.

class Menu(models.Model):
    name=models.CharField(max_length=30)
    description=models.CharField(max_length=255)
    position=models.IntegerField()
    alternative_url=models.URLField(blank=True,null=True)
    online=models.BooleanField()
    def __unicode__(self):
        return self.name

class Catalog(models.Model):
    name=models.CharField(max_length=30)
    description=models.CharField(max_length=255)
    position=models.IntegerField()
    alternative_url=models.URLField(blank=True,null=True)
    menu=models.ForeignKey(Menu)
    online=models.BooleanField()


    def __unicode__(self):
        return u'%s , %s' %(self.name,self.online)
    class Meta:
        ordering=['position']


class Article(models.Model):
    title=models.CharField(max_length=60)
    content=models.TextField()
    create_at=models.DateTimeField(auto_now=True)
    catalogs=models.ManyToManyField(Catalog)
    online=models.BooleanField()
    def __unicode__(self):
        return u'%s , %s' %(self.title,self.online)
    class Meta:
        ordering=['create_at']
    def fmt_date(self):
        format="%Y-%m-%d"
        return self.create_at.date().strftime(format)
    
